import { defineStore } from 'pinia'

export const useExamResultStore = defineStore('examResult', {
  state: () => ({
    totalQuestions: 0,
    answeredQuestions: 0,
    correctAnswers: 0,
    score: 0,
    details: [] as any[],
    examStartTime: 0,     // 考试开始时间
    examEndTime: 0,       // 考试结束时间
    examDuration: 0       // 考试耗时(秒)
  }),
  
  actions: {
    setResult(result: {
      totalQuestions: number,
      answeredQuestions: number,
      correctAnswers: number,
      score: number,
      details: any[],
      examStartTime?: number,
      examEndTime?: number,
      examDuration?: number
    }) {
      this.totalQuestions = result.totalQuestions
      this.answeredQuestions = result.answeredQuestions
      this.correctAnswers = result.correctAnswers
      this.score = result.score
      this.details = result.details
      this.examStartTime = result.examStartTime || 0
      this.examEndTime = result.examEndTime || 0
      this.examDuration = result.examDuration || 0
    },
    
    clearResult() {
      this.totalQuestions = 0
      this.answeredQuestions = 0
      this.correctAnswers = 0
      this.score = 0
      this.details = []
      this.examStartTime = 0
      this.examEndTime = 0
      this.examDuration = 0
    }
  }
})